package com.hmall.search.listener;

import com.hmall.search.service.ISearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Mr_Su
 * @version v1.0
 * @date 2022/6/22 12:46
 * @desciption
 */
@Component
public class ItemListener {

    @Autowired
    private ISearchService iSearchService;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "item.up.queue"),
            exchange = @Exchange(name = "item.topic", type = ExchangeTypes.TOPIC),
            key = "item.up"
    ))
    public void itemUp(Long id) {
        iSearchService.itemUp(id);
    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "item.down.queue"),
            exchange = @Exchange(name = "item.topic", type = ExchangeTypes.TOPIC),
            key = "item.down"
    ))
    public void itemDown(String itemIdString) {
        iSearchService.itemDown(itemIdString);
    }
}
